package com.spark.gaea.utils.json;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.cfg.PackageVersion;
import com.fasterxml.jackson.databind.module.SimpleModule;

import java.util.Date;

public final class JsonUtil {
	private static final ObjectMapper _mapper;

	public static ObjectMapper getMapper() {
		return JsonUtil._mapper;
	}

	static {
		_mapper = new ObjectMapper();
		final SimpleModule newModule = new SimpleModule("DataModule", PackageVersion.VERSION);
		final DateDeserializer dateDeserializer = new DateDeserializer();
		final DateSerializer dateSerializer = new DateSerializer();
		newModule.addDeserializer(Date.class, dateDeserializer);
		newModule.addSerializer(Date.class, dateSerializer);
		JsonUtil._mapper.registerModule(newModule);
	}
}
